package com.googlecode.wheres_my_stuff_okay_potato;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

/**
 * A fragment that brings up a dialog box containing multiple categories a user
 * can filter a list of items by.
 * 
 * @author Jeremy Hehn
 */
public class CategoryPickerFragment extends DialogFragment {
	private String selectedCategory = "Other";

	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
		builder.setTitle(R.string.category_picker_title);

		// Specify the list array, the items to be selected by default (null for
		// none),
		// and the listener through which to receive callbacks when items are
		// selected
		builder.setSingleChoiceItems(R.array.categories_array, -1,
				new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface d, int which) {
						switch (which) {
						case 0:
							selectedCategory = "Books";
							break;
						case 1:
							selectedCategory = "Documents/Papers";
							break;
						case 2:
							selectedCategory = "Jewelry";
							break;
						case 3:
							selectedCategory = "Other";
							break;
						}
					}
				})
				.setPositiveButton(R.string.submit,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int id) {
								return;
							}
						})
				.setNegativeButton(R.string.cancel,
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int id) {
								// Do nothing and close the dialog
								return;
							}
						});

		return builder.create();
	}

	/**
	 * Returns the currently selected category. Defaults to returning "Other" if
	 * no category has been selected.
	 * 
	 * @return the category the user most recently selected.
	 */
	public String getCategory() {
		return selectedCategory;
	}
}